#include <stdio.h>
#include <iostream>

using namespace std;

int byte[1000];
int m;
int addr, mask;

int getbit(int n, int b)
{
	return (n >> b) & 1;
}

void xorbit(int *n, int b)
{
	*n = *n ^ (1 << b);
}

int main()
{
	scanf("%d", &m);
	for (int i=0; i < m; i++)
	{
		int b0, b1, b2, b3;
		scanf("%d.%d.%d.%d", &b0, &b1, &b2, &b3);
		byte[i] = (b0 << 24) ^ (b1 << 16) ^ (b2 << 8) ^ b3;
		cerr << byte[i] << endl;
	}

	addr = 0;
	mask = 0;
	bool ok = true;
	for (int bit = 31; bit >= 0; bit--)
	{
		int bit0 = getbit(byte[0], bit);

		for (int j = 1; j < m; j++) 	
			if (getbit(byte[j], bit) != bit0)
			{
				ok = false;
				break;
			}
			
		if (ok) 
		{
			xorbit(&mask, bit);
			if (bit0 == 1) xorbit(&addr, bit);
		}
		else break;
	}

	printf("%d.%d.%d.%d\n", (addr >> 24) & 255, (addr >> 16) & 255, (addr >> 8) & 255, addr & 255);
	printf("%d.%d.%d.%d", (mask >> 24) & 255, (mask >> 16) & 255, (mask >> 8) & 255, mask & 255);

	return 0;
}
